home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / pascal / timicon.exe / TIMICON.PAS < prev   
Encoding:
Pascal/Delphi Source File  |  1991-07-20  |  5.6 KB  |  205 lines

  1. {*************************************************************************************
  2.  Creator:  Jack C. Mackey
  3.  Program:  TIMICON - Time Watch Icon
  4.  Date   :  07/19/91
  5.  Comments:
  6.    An example program, implementing the techniques used to create the
  7.    FREEMEM program delineated in 'Progamming Windows 3' C. Petzold.
  8.  
  9.    Use at your own risk. There is no implied warranty of any kind.
  10.  
  11.    TIMICON will display a default program ICON and the current
  12.    time within. The current time is displayed with 'AM' or 'PM'.
  13.  
  14.    I hope this will be of some use to those heading down the TPW road.
  15.  *************************************************************************************}
  16.  
  17.  
  18. USES windos,strings,wintypes,winprocs;
  19.  
  20.  
  21.  
  22. FUNCTION winproc(window : hwnd;
  23.                  message: word;
  24.                  wparam : word;
  25.                  lparam : longint) : longint; export;
  26. CONST
  27.   minupdate: word = 1; {update Icon every minupdate mins.}
  28.   twhour   : word = 0; {current hour}
  29.   twphour  : word = 0; {previous hour}
  30.   twmin    : word = 0; {current mins.}
  31.   twpmin   : word = 0; {previous mins.}
  32.   twsec    : word = 0;
  33.   twsec100 : word = 0;
  34.                       {12345678901234567890}
  35.   pbufr   : pchar   = '                    ';
  36.   fid_timer = 1;
  37.   frect : trect = (left  : 0;
  38.                    top   : 0;
  39.                    right : 0;
  40.                    bottom: 0);
  41. VAR
  42.   devcont  : hdc;
  43.   ps       : tpaintstruct;
  44.   tempstr  : string[20];
  45.   twminstr : string[3];
  46.   clen     : integer;
  47.   prnthour : word;
  48.   twampm   : string[4];
  49.  
  50. BEGIN
  51.   winproc := 0;
  52.   CASE message
  53.   OF
  54.     wm_timer: BEGIN
  55.                 gettime(twhour,twmin,twsec,twsec100);
  56.                 IF (twhour - twphour <> 0)
  57.                 OR (twmin  - twpmin  >=  minupdate)
  58.                 THEN
  59.                 BEGIN
  60.                   invalidaterect(window, nil, true);
  61.                   twphour  := twhour;
  62.                   twpmin   := twmin;
  63.                 END;
  64.               END;
  65.     wm_size : BEGIN
  66.                 getclientrect(window,frect);
  67.               END;
  68.     wm_paint: BEGIN
  69.                 devcont := beginpaint(window,ps);
  70.                 tempstr := '';
  71.                 twminstr:= '';
  72.                 prnthour := twhour mod 12;
  73.                 IF   twhour = 0
  74.                 THEN prnthour := 12;
  75.                 IF twhour > 11
  76.                 THEN twampm := '  PM'
  77.                 ELSE twampm := '  AM';
  78.                 str(prnthour:2, tempstr);
  79.                 IF tempstr[1] = ' '
  80.                 THEN tempstr[1] := '0';
  81.                 str(twmin:2,twminstr);
  82.                 IF twminstr[1] = ' '
  83.                 THEN twminstr[1] := '0';
  84.                 tempstr := concat(tempstr,strpas(':'));
  85.                 tempstr := concat(tempstr,twminstr);
  86.                 tempstr := concat(tempstr,twampm);
  87.                 strpcopy(pbufr,tempstr);
  88.                 clen := length(tempstr);
  89.                 drawtext(devcont,pbufr,clen,frect,dt_wordbreak);
  90.                 endpaint(window,ps);
  91.               END;
  92.     wm_queryopen: BEGIN
  93.                   END;
  94.     wm_destroy: BEGIN
  95.                   killtimer(window,fid_timer);
  96.                   postquitmessage(0);
  97.                 END;
  98.     ELSE
  99.     BEGIN
  100.       winproc := defwindowproc(window,message,wparam,lparam);
  101.     END;
  102.   END;
  103. END;
  104.  
  105. PROCEDURE winmain;
  106. CONST
  107.   appname   = 'Time Watch';
  108.   idm_about = 100;
  109.   fid_timer = 1;
  110.   wclass : twndclass =(style        : 0;
  111.                        lpfnwndproc  : nil;
  112.                        cbclsextra   : 0;
  113.                        cbwndextra   : 0;
  114.                        hinstance    : 0;
  115.                        hicon        : 0;
  116.                        hcursor      : 0;
  117.                        hbrbackground: 0;
  118.                        lpszmenuname : appname;
  119.                        lpszclassname: appname);
  120.  
  121.  
  122. VAR
  123.   window : hwnd;
  124.   message: tmsg;
  125.   devcont: hdc;
  126.   tm     : ttextmetric;
  127. BEGIN
  128.   IF hprevinst = 0
  129.   THEN
  130.   BEGIN
  131.     wclass.style       := cs_hredraw xor cs_vredraw;
  132.     wclass.lpfnwndproc := @winproc;
  133.     wclass.cbclsextra  := 0;
  134.     wclass.cbwndextra  := 0;
  135.     wclass.hinstance   := hinstance;
  136.     wclass.hicon       := 0;
  137.     wclass.hcursor     := loadcursor(0,idc_arrow);
  138.     wclass.hbrbackground:=getstockobject(white_brush);
  139.     wclass.lpszclassname:= appname;
  140.     IF registerclass(wclass) = false
  141.     THEN
  142.     BEGIN
  143.        halt(255);
  144.        {error registering class}
  145.     END;
  146.     window := createwindow(appname,'TP-Watch',
  147.                            ws_overlappedwindow,
  148.                            cw_usedefault, cw_usedefault,
  149.                            cw_usedefault, cw_usedefault,
  150.                            0,0,hinstance,nil);
  151.     devcont := getdc(window);
  152.     gettextmetrics(devcont, tm);
  153.     releasedc(window,devcont);
  154.     IF (4 * tm.tmavecharwidth > getsystemmetrics(sm_cxicon))
  155.     OR (2 * tm.tmheight       > getsystemmetrics(sm_cyicon))
  156.     THEN
  157.     BEGIN
  158.       messagebox(window,'Icon is to small for Free Memory Display',
  159.                  appname, mb_iconexclamation xor mb_ok);
  160.     END
  161.     ELSE
  162.     BEGIN
  163.       IF settimer(window,fid_timer,1000,nil) = 0
  164.       THEN
  165.       BEGIN
  166.         messagebox(window,'Cannot Set timer for Free Memory Display',
  167.                    appname, mb_iconexclamation xor mb_ok);
  168.       END
  169.       ELSE
  170.       BEGIN
  171.         showwindow(window,sw_showminnoactive);
  172.         updatewindow(window);
  173.         WHILE getmessage(message,0,0,0) = true
  174.         DO
  175.         BEGIN
  176.           translatemessage(message);
  177.           dispatchmessage(message);
  178.         END;
  179.       END;
  180.     END;
  181.   END;
  182. END;
  183.  
  184.  
  185.  
  186. BEGIN
  187.   winmain;
  188. END.
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.